#!/bin/csh

set COND_FILE = /occ/tmp/.conditions

set SHO_ACTION = 1
set SET_ACTION = 2
set HLP_ACTION = 3

if (${#argv} < 1) then    
    echo "oss_seeing SET <seeing> <photom>"
    echo "      seeing = [POOR | AVERAGE | EXCELLENT] "
    echo "      photom = [SPECTRO | PHOTOM] "
    echo "oss_seeing SHOW"
    exit 0
endif

switch ($1)
    case "SHOW":

    if (! -e $COND_FILE) then
	echo "Warning: There is no conditions file: $COND_FILE "
	exit 1
    endif

    set action = $SHO_ACTION
    set SVAL = `cat ${COND_FILE} | grep "seeing" | cut -d"=" -f2`
    set PVAL = `cat ${COND_FILE} | grep "extinction" | cut -d"=" -f2`

    breaksw
    case "SET":
    
    set action = $SET_ACTION
    set SVAL = $2
    set PVAL = $3
    breaksw

endsw
    
switch ($SVAL)
  case "POOR":
	set SCOND = "seeing = POOR"
	set sdesc = "[Poor seeing ( > 1.3as)]"
	breaksw 
    case "AVERAGE":
	set SCOND = "seeing = AVERAGE"
	set sdesc = "[Average seeing (0.8as - 1.3as)]"
	breaksw
    case "GOOD":
    case "EXCELLENT": 
	set SCOND = "seeing = EXCELLENT"
	set sdesc = "[Excellent seeing (< 0.8as)]"
	breaksw
    default:
	set SCOND = "seeing = POOR"
	set sdesc = "[Default Poor seeing ( > 1.3as)]"
endsw

switch ($PVAL)
    case "spectroscopic":
	set PCOND = "extinction = SPECTRO"
	set pdesc = "[Spectroscopic extinction]"
	breaksw
    default:
	set PCOND = "extinction = PHOTOM"
	set pdesc = "[Photometric extinction]"
	breaksw
endsw


switch ($action)
    case ${SET_ACTION}:
	echo "Updating conditions to: $sdesc $pdesc"
	echo $SCOND >!  $COND_FILE
	echo $PCOND >>! $COND_FILE
	breaksw
    case ${SHO_ACTION}:
	echo "Using conditions: Seeing: $sdesc Photom: $pdesc"
	breaksw
endsw

